# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        Young  
# Name:         task12_1
# Description:
# Author:       $赵怡蕾
# Date:         2019/4/10
#-------------------------------------------------------------------------------

'''
斗地主
要求1号的牌最好
采用面向对象的方法写
'''

order = 1  # 牌排列顺序 默认为1 即从小到大顺序排列  0：从大到小排列
Player_Num = 3  # 三名玩家
N = 54  # 一副牌有54张（包含大小王）
times = 1  # 一副牌
leftover = 3  # 3张底牌

import random

card0 = list(range(0, N))
card0 = card0 * times
# print(card0)
schar = '♠♥♣♦♛♚'
card1 = []
left = N * times
for i in range(N * times):
    rdi = random.randint(0, left - 1)
    card1.append(card0[rdi])
    card0.pop(rdi)
    left -= 1
    if left == 0:
        break
# print(card1)
Player = []
for i in range(Player_Num):
    Player.append([])
for i in range(N * times - leftover):
    Player[i % Player_Num].append(card1[i])
Player.append([])
for i in range(N * times - leftover, N * times):
    Player[Player_Num].append(card1[i])
for i in range(Player_Num + 1):
       # print(Player[i])
    Player[i].sort()
    if order == 0:
        Player[i].reverse()
   # print(Player[i])
card_output = []
for i in range(Player_Num + 1):
    card_output.append([])
for i in range(Player_Num + 1):
    for j in range(len(Player[i])):
        if Player[i][j] == 53 or Player[i][j] == 52:
            card_output[i].append(str(schar[Player[i][j] % 2 + 4]).rjust(3))
        else:
            cardnumber = (Player[i][j] // 4 + 2) % 13 + 1
            cardflower = 3 - Player[i][j] % 4
            if cardnumber == 1:
                card_output[i].append('A'.rjust(2) + str(schar[cardflower]))
            elif cardnumber == 11:
                card_output[i].append('J'.rjust(2) + str(schar[cardflower]))
            elif cardnumber == 12:
                card_output[i].append('Q'.rjust(2) + str(schar[cardflower]))
            elif cardnumber == 13:
                card_output[i].append('K'.rjust(2) + str(schar[cardflower]))
            else:
                card_output[i].append(str(cardnumber).rjust(2) + str(schar[cardflower]))
# print(card_output)
for i in range(Player_Num):
    print('玩家{:>2}的手牌为:'.format(i + 1), ' '.join(card_output[i]))
print('剩余的{}张底牌为:'.format(leftover), ' '.join(card_output[Player_Num]))